<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:a4j="http://richfaces.org/a4j" template="layout/template.xhtml">

	<ui:define name="body">

		<p:messages globalOnly="true" styleClass="message" />

		<h:form id="frmHome">
			<rich:panel>
				<f:facet name="header">Bem vindo</f:facet>
				<h1>Registros de Serviços Vinculados ao usuário logado:</h1>
				<br />


				<rich:dataTable
					value="#{servicoAction.carregarServicoNaoFinalizadoPorTecnico(identity.usuario.id)}"
					var="servico" rows="10" reRender="ds" id="simpletable"
					rendered="#{servicoAction.carregarServicoNaoFinalizadoPorTecnico(identity.usuario.id).size > 0}"
					columnClasses="center"
					onRowMouseOver="this.style.backgroundColor='#b2d5d6'"
					onRowMouseOut="this.style.backgroundColor='#FFFFFF'">
					<f:facet name="header">
						<h:outputText value="Serviços" />
					</f:facet>
					<rich:column sortBy="#{servico.numOrdemServico}">
						<f:facet name="header">
							<h:outputText value="Número OS" />
						</f:facet>
						<h:outputText value="#{servico.numOrdemServico}" />
					</rich:column>

					<rich:column sortBy="#{servico.dtaAtendimento}">
						<f:facet name="header">
							<h:outputText value="Data Atendimento" />
						</f:facet>
						<h:outputText value="#{servico.dtaAtendimento}">
							<s:convertDateTime pattern="dd/MM/yyyy"></s:convertDateTime>
						</h:outputText>
					</rich:column>

					<rich:column sortBy="#{servico.cliente.nome}">
						<f:facet name="header">
							<h:outputText value="Cliente" />
						</f:facet>
						<h:outputText value="#{servico.cliente.nome}" />
					</rich:column>

					<rich:column sortBy="#{servico.descrEquipamento}">
						<f:facet name="header">
							<h:outputText value="Descrição Equipamento" />
						</f:facet>
						<h:outputText value="#{servico.descrEquipamento}" />
					</rich:column>

					<rich:column sortBy="#{servico.defeitoDeclarado}">
						<f:facet name="header">
							<h:outputText value="Defeito Declarado" />
						</f:facet>
						<h:outputText value="#{servico.defeitoDeclarado}" />
					</rich:column>

					<rich:column sortBy="#{servico.tipoServico.descricao}">
						<f:facet name="header">
							<h:outputText value="Tipo Serviço" />
						</f:facet>
						<h:outputText value="#{servico.tipoServico.descricao}" />
					</rich:column>

					<rich:column sortBy="#{servico.servicoStatus.descricao}">
						<f:facet name="header">
							<h:outputText value="Status Serviço" />
						</f:facet>
						<h:outputText value="#{servico.servicoStatus.descricao}" />
					</rich:column>
					<rich:column style="text-align: center;">
						<f:facet name="header">
							<h:outputText value="Visualizar" />
						</f:facet>
						<a4j:commandLink
							action="#{servicoAction.selecionarCliente(cliente)}"
							onclick="Richfaces.showModalPanel('mdOS');" reRender="frmNovaOS">
							<h:graphicImage value="/img/ico_busca_24.gif"
								style="border: none;" alt="Detalhes" title="Visualizar Detalhes"
								width="16px" />
						</a4j:commandLink>
					</rich:column>


					<f:facet name="footer">
						<rich:datascroller id="ds"></rich:datascroller>
					</f:facet>
				</rich:dataTable>
				<s:fragment
					rendered="#{servicoAction.carregarServicoNaoFinalizadoPorTecnico(identity.usuario.id).size == 0}">
						Não existem serviços para esse usuário.
					</s:fragment>



			</rich:panel>

		</h:form>


		<!-- FORM MODAL PARA APRESENTACAO DE NOVA ORDEM DE SERVICOS -->

		<rich:modalPanel id="mdOS" width="1000" height="490">
			<f:facet name="header">
				<h:panelGroup>
					<h:outputText value="Nova OS"></h:outputText>
				</h:panelGroup>
			</f:facet>
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" styleClass="hidelink"
						id="hidelinkOS" />
					<rich:componentControl for="mdOS" attachTo="hidelinkOS"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>

			<h:form id="frmNovaOS">
				<rich:tabPanel switchType="client">
					<rich:tab label="Informações sobre o Orçamento">

						<s:decorate id="NumOSField" template="/layout/edit.xhtml">
							<ui:define name="label">Num OS:</ui:define>
							<h:outputText id="numOSGerado" value="#{servico.numOrdemServico}" />
						</s:decorate>

						<s:decorate id="clienteNomeField" template="/layout/edit.xhtml">
							<ui:define name="label">Cliente:</ui:define>
							<h:outputText id="nomeCliente" value="#{servico.cliente.nome}" />
						</s:decorate>

						<s:decorate id="clienteCpfField" template="/layout/edit.xhtml">
							<ui:define name="label">CPF:</ui:define>
							<h:outputText id="cpfCliente" value="#{servico.cliente.cpf}" />
						</s:decorate>

						<s:decorate id="descrEquipamentoField"
							template="/layout/edit.xhtml">
							<ui:define name="label">Descrição do Equipamento:</ui:define>
							<h:outputText id="descEquipamento"
								value="#{servico.descrEquipamento}" />
						</s:decorate>

						<s:decorate id="marcaField" template="/layout/edit.xhtml">
							<ui:define name="label">Marca:</ui:define>
							<h:outputText id="marca" value="#{servico.marca}" />
						</s:decorate>

						<s:decorate id="modeloField" template="/layout/edit.xhtml">
							<ui:define name="label">Modelo:</ui:define>
							<h:outputText id="modelo" value="#{servico.modelo}" />
						</s:decorate>

						<s:decorate id="defeitoDeclaradoField"
							template="/layout/edit.xhtml">
							<ui:define name="label">Defeito declarado:</ui:define>
							<h:outputText id="defeitoDeclarado"
								value="#{servico.defeitoDeclarado}" />
						</s:decorate>

						<s:decorate id="tipoServicoField" template="/layout/edit.xhtml">
							<ui:define name="label">Tipo Serviço:</ui:define>
							<h:outputText id="tipoServico"
								value="#{servico.tipoServico.descricao}" />
						</s:decorate>

						<s:decorate id="statusServicoLabel" template="/layout/edit.xhtml">
							<ui:define name="label">Status Serviço:</ui:define>
							<h:outputText id="statusServicoL"
								value="#{servico.servicoStatus.descricao}" />
						</s:decorate>


						<div style="clear: both" />
						<br />
						<br />

					</rich:tab>
					<rich:tab label="Orçamento Técnico">

						<s:decorate id="defeitoEncontradoField"
							template="/layout/edit.xhtml">
							<ui:define name="label">Defeito encontrado:</ui:define>

							<p:inplace
								label="#{servico.defeitoEncontrado.length() > 0 ? servico.defeitoEncontrado : 'Clique aqui para adicionar o defeito encontrado'}">
								<h:inputTextarea id="defeitoEncontrado"
									value="#{servico.defeitoEncontrado}" required="false" cols="70"
									rows="2" />
							</p:inplace>
						</s:decorate>

						<s:decorate id="solucaoField" template="/layout/edit.xhtml">
							<ui:define name="label">Solução:</ui:define>
							<p:inplace
								label="#{servico.solucao.length() > 0 ? servico.solucao : 'Clique aqui para adicionar o solução encontrada'}">
								<h:inputTextarea id="solucao" value="#{servico.solucao}"
									required="false" cols="70" rows="2" />
							</p:inplace>
						</s:decorate>

						<s:decorate id="valorMaoObraField" template="/layout/edit.xhtml">
							<ui:define name="label">Valor Mão de Obra:</ui:define>
							<p:inplace label="#{servico.valorMaoObra.toString().length() > 0 ? servico.valorMaoObra : 'Clique aqui para adicionar o valor da mão de obra'}">
							<h:inputText id="valorMaoObra" size="10"
								value="#{servico.valorMaoObra}" required="false"/>
								</p:inplace>
						</s:decorate>

						<s:decorate id="observacaoField" template="/layout/edit.xhtml">
							<ui:define name="label">Observação:</ui:define>
							<p:inplace label="#{servico.observacao.length() > 0 ? servico.observacao : 'Clique aqui para adicionar uma observação retativa a OS'}">
							<h:inputTextarea id="observacao" value="#{servico.observacao}"
								cols="70" rows="2"/>
							</p:inplace>	
						</s:decorate>

						<s:decorate id="statusServicoField" template="/layout/edit.xhtml">
							<ui:define name="label">Status Serviço:</ui:define>
							<h:selectOneMenu value="#{servico.servicoStatus}"
								required="false" id="sStatus">
								<s:selectItems var="status"
									value="#{servicoStatusAction.carregarTodos()}"
									label="#{status.descricao}" noSelectionLabel="-- Selecione --"></s:selectItems>
								<s:convertEntity></s:convertEntity>
								<a4j:support event="onblur" reRender="statusServicoField"
									bypassUpdates="true" ajaxSingle="true" status="none" />
							</h:selectOneMenu>
						</s:decorate>

						<br />
						<br />
						<div style="clear: both"><span class="required">*</span>
						Campos requeridos</div>

						<div style="clear: both" />
						<br />
						<br />

						<div class="actionButtons"><a4j:commandButton value="Salvar"
							style=" width : 100px;"
							action="#{servicoAction.alterar(servico)}"
							rendered="#{servico.id != null}" reRender="frmNovaOS" /> <h:commandButton
							value="#{messages['btnCancel']}" style="width : 100px;"
							action="#{servicoAction.cancelar()}" /></div>



					</rich:tab>
					<rich:tab label="Peças / Materiais">
						<h:form>
						<h:inputText value="Pesquisar peças"/>

							<rich:dataTable value="#{pecaAction.carregarTodos()}" var="peca"
								rows="10" reRender="ds" id="simpletable"
								rendered="#{pecaAction.carregarTodos().size > 0}"
								columnClasses="center"
								onRowMouseOver="this.style.backgroundColor='#b2d5d6'"
								onRowMouseOut="this.style.backgroundColor='#FFFFFF'">
								<f:facet name="header">
									<h:outputText value="Peças" />
								</f:facet>
								<rich:column sortBy="#{peca.descricao}" filterBy="#{peca.descricao}">
									<f:facet name="header">
										<h:outputText value="Descrição" />
									</f:facet>
									<h:outputText value="#{peca.descricao}" />
								</rich:column>

								<rich:column sortBy="#{peca.valor}">
									<f:facet name="header">
										<h:outputText value="Valor" />
									</f:facet>
									<h:outputText value="#{peca.valor}">
										<f:convertNumber pattern="#,##0.00" />
									</h:outputText>
								</rich:column>

								<rich:column style="text-align: center;"
									rendered="#{identity.hasRole('admin')}">
									<f:facet name="header">
										<h:outputText value="Editar" />
									</f:facet>
									<a4j:commandLink action="#{pecaAction.selecionarPeca(peca)}"
										reRender="pecaForm">
										<h:graphicImage value="/img/ico_altera_16.gif"
											style="border: none;" alt="Alterar" title="Alterar Registro" />
									</a4j:commandLink>
								</rich:column>
								<rich:column style="text-align: center;"
									rendered="#{identity.hasRole('admin')}">
									<f:facet name="header">
										<h:outputText value="Apagar" />
									</f:facet>
									<a4j:commandLink action="#{pecaAction.excluir(peca)}"
										reRender="simpletable,pecaForm"
										onclick="if(!confirm('Confirma Exclus&#227;o?')){return false;}">
										<h:graphicImage value="/img/ico_apaga_16.gif"
											style="border: none;" alt="Excluir" title="Excluir Registro" />
									</a4j:commandLink>
								</rich:column>


								<f:facet name="footer">
									<rich:datascroller id="ds"></rich:datascroller>
								</f:facet>
							</rich:dataTable>

						</h:form>


					</rich:tab>
				</rich:tabPanel>
			</h:form>
		</rich:modalPanel>

	</ui:define>
</ui:composition>
